package com.negative.logic;

import java.util.ArrayList;

import com.negative.activities.R;
import com.negative.data.OrderTicketDetailsData;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class TicketListAdapter extends BaseAdapter{

	private LayoutInflater vi;
	private ArrayList<OrderTicketDetailsData> data;
	private String totalPrice;
	
	public TicketListAdapter(Context context, ArrayList<OrderTicketDetailsData> data, String totalPrice) {
		this.data = data;
		this.data.add(0, new OrderTicketDetailsData("", "", "", ""));
		this.totalPrice = totalPrice;
		vi = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size() + 1;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		View v = vi.inflate(R.layout.payment_form_ticket_list_entry, null);
		
		TextView amount = (TextView) v.findViewById(R.id.payment_form_email_label);
		TextView type = (TextView) v.findViewById(R.id.payment_form_personal_info_header);
		TextView price = (TextView) v.findViewById(R.id.payment_form_tickets_header);
		TextView total = (TextView) v.findViewById(R.id.payment_form_order_header);
		
		if (position == 0) {
			amount.setText(v.getContext().getString(R.string.ticketAmount));
			type.setText(v.getContext().getString(R.string.ticketType));
			price.setText(v.getContext().getString(R.string.ticketPrice));
			total.setText(v.getContext().getString(R.string.ticket_list_adapter_total_price));
		} else if (position < data.size()){
			amount.setText(data.get(position).getAmount());
			type.setText(data.get(position).getTicketType());
			price.setText(data.get(position).getPrice());
			total.setText(data.get(position).getRowTotal());
		} else {
			amount.setText("");
			price.setText("");
			type.setText("");
			total.setText(totalPrice);
		}
		
		return v;
	}

}
